<?php
namespace App\Models;

use App\Jobs\Fun;

/**
* This is the model class for table "news".
 * @property int10unsigned id	主键id
 * @property int10unsigned cid	公司UID
 * @property varchar100 title	标题
 * @property varchar255 desc	描述
 * @property longtext content	内容
 * @property varchar255 thumb	封面
 * @property int10unsigned praise	点赞次数
 * @property int2 status	状态 1删除
 * @property int10unsigned created_at	创建时间
 * @property int10unsigned updated_at	更新时间
 */
class NewsModel extends Model
{
    protected $table = 'news';

    public function attributeLabels() {
        return [
            'id' => 'id',
            'cid' => '用户id',
            'title' => '标题',
            'thumb' => '封面图',//
            'created_at' => '时间',
            'status' => '是否隐藏',///如果为0，表示禁止执行，非0表示可以执行
            'praise' => '点赞',
            'desc'=>'简介',
            'content'=>'内容',
            'paixu'=>'排序',
            'pv'=>'浏览量'

        ];
    }
    const status_show=0;
    const status_hide=1;

    public static function addNews($uid,$title,$thumb,$content){
        $new=new self;
        $new->status=self::status_show;
        $new->cid=$uid;
        $new->title=$title;
        $new->thumb=$thumb;
        $new->content=$content;
        $new->praise=0;

        $new->created_at=time();
        $new->updated_at=time();
        $new->desc=Fun::shenglue($content,32);
        if($new->save()){
            return $new->id;
        }else{
            return false;
        }
    }
    public static function getstatus($status=null){
        $list=[
            self::status_show=>'显示',
            self::status_hide=>'隐藏',

        ];
        if($status===null){
            return $list;
        }
        return isset($list[$status])?$list[$status]:'';
    }


}